<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @cancel="handleCancel"
  >
    <template slot="footer">
      <div v-show="title == '审核'">
        <a-button key="back" @click="handleCancel">关闭</a-button>
        <a-button key="submit" type="primary" @click="handleApp(1)"> 通过</a-button>
      </div>
      <div v-show="title == '详情'">
        <a-button key="back" @click="handleCancel"> 关闭</a-button>
      </div>
    </template>
    <shipment-goods-bill-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" />
  </j-modal>
</template>

<script>
import ShipmentGoodsBillForm from './ShipmentGoodsBillForm'
import { putShipmentGoodsBill } from '@/api/order'

export default {
  name: 'ShipmentGoodsBillModal',
  components: {
    ShipmentGoodsBillForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      record: {},
    }
  },
  methods: {
    handleApp(type) {
      debugger
      putShipmentGoodsBill({ id: this.record.id, storeId: this.record.storeId }).then((res) => {
        let { message, success } = res
        if (success) {
          this.$message.success(message)
          this.$emit('ok')
          this.close()
        } else {
          this.$message.warning(message)
        }
      })
    },
    add() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      this.record = record
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.handleOk()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>